<template>
    <div class="list_page_div">
        <page-list :loading="loading" :table-config="tableConfig" :data-list="dataList" :height="height" show-index
                   show-page :total="total" :pageSize="param.pageSize" :currentPage="param.pageNum" @currentChange="handleCurrentChange"
                   show-operate operate-width="200px">
            <template #searchArea>
                <select-option v-model="param.flowableCode" placeholder="流程烦劳" select-width="200px" :list="flowTypeList"></select-option>
                <el-input v-model="param.modelName" clearable placeholder="模型名称" style="width: 200px;"></el-input>
                <el-button type="primary" @click="searchList">查询</el-button>
                <el-button type="primary" @click="resetData">重置</el-button>
                <el-button v-if="powerList.indexOf('flowModel:insert')>-1" type="primary" @click="editData()">新增
                </el-button>
            </template>

            <template #operateContent="scope">
                <el-button v-if="powerList.indexOf('flowModel:update')>-1" type="text" @click="editData(scope.row.id)">编辑</el-button>
                <el-popconfirm v-if="powerList.indexOf('flowModel:delete')>-1" title="是否确定删除当前数据？"  @confirm="delData(scope.row.id)">
                    <el-button slot="reference" type="text">删除</el-button>
                </el-popconfirm>
                <el-button v-if="powerList.indexOf('flowModel:design')>-1" type="text" @click="designData(scope.row)">设计</el-button>
                <el-button v-if="powerList.indexOf('flowModel:arrange')>-1" type="text" @click="arrangeData(scope.row.id)">部署</el-button>
            </template>
        </page-list>
        <model-edit :visible.sync="showEdit" :id="id" @refreshList="searchList"></model-edit>
        <flow-image :visible.sync="showDesign" :id="id" :model-idl="modelId" :flowable-code="flowableCode" @refreshList="searchList"></flow-image>
    </div>
</template>

<script>
import PageList from "@/components/grid/pageList.vue";
import SelectOption from "@/components/select/selectOption.vue";
import ModelEdit from "./compnent/modelEdit.vue";
import FlowImage from "./compnent/flowableImage.vue";

export default {
    name: 'modelList',
    components: {FlowImage, ModelEdit, SelectOption, PageList},
    data() {
        return {
            height: '500px',
            loading: false,
            showEdit: false,
            showDesign: false,

            id: '',
            modelId: '',
            flowableCode: '',
            tableConfig: [
                {label: "流程类型", prop: "flowableName", width: 160},
                {label: "模型编号", prop: "modelKey", width: 240},
                {label: "模型名称", prop: "modelName", minWidth: 200},
                {label: "组织机构", prop: "organizeName", width: 200},
                {label: "更新时间", prop: "operateTime", width: 200},
                {label: "发布时间", prop: "releaseTime", width: 200},
            ],
            dataList: [],
            total: 0,
            param: {
                flowableCode: '',
                modelName: '',
                field: 'create_time',
                order: 'desc',
                pageSize: 20,
                pageNum: 1,
            },
            flowTypeList: [],

            powerList: [],
        }
    },
    mounted() {
        this.getFlowTypeList();
        this.$nextTick(() => {
            this.powerList = this.$common.getPowerList("model");
            this.height = (document.body.offsetHeight - 185) + "px";
        })
        this.searchList();
    },
    methods: {
        getFlowTypeList() {
            this.loading = true;
            this.$axios.post('/CHILD_CONFIG/baseFlowType/getAllList').then(res => {
                this.flowTypeList = this.$common.getSelectList(res.data, "flowableName", "flowableCode");
                this.loading = false;
            }).catch(() => {
                this.loading = false;
            })
        },
        handleCurrentChange(val) {
            this.param.pageNum = val;
            this.searchList();
        },
        resetData() {
            this.param.flowableCode = '';
            this.param.modelName = '';
            this.param.pageNum = 1;
            this.searchList();
        },
        searchList() {
            this.loading = true;
            this.$axios.post("/CHILD_WORKFLOW/flowModel/getPageList", this.param).then(res => {
                this.total = res.data.total;
                this.dataList = res.data.rows;
                this.loading = false;
            }).catch(() => {
                this.loading = false;
            })
        },
        editData(id) {
            this.id = id;
            this.showEdit = true;
        },
        delData(id) {
            this.loading = true;
            this.$axios.post("/CHILD_WORKFLOW/flowModel/delete/" + id).then(res => {
                this.searchList();
                this.$message.success("删除成功！");
            }).catch(() => {
                this.loading = false;
            })
        },
        designData(row) {
            this.id = row.id;
            this.modelId = row.modelId;
            this.flowableCode = row.flowableCode;
            this.showDesign = true;
        },
        arrangeData(id) {
            this.loading = true;
            this.$axios.post("/CHILD_WORKFLOW/flowModel/arrange/" + id).then(res => {
                this.searchList();
                this.$message.success("删除成功！");
            }).catch(() => {
                this.loading = false;
            })
        },
    }
}
</script>

<style lang="scss">

</style>